<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page isELIgnored="true" %>
<!-- 论坛中心 -->
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<title>论坛中心</title>
		<link rel="stylesheet" href="../../layui/css/layui.css">
		<!-- 样式 -->
		<link rel="stylesheet" href="../../css/style.css" />
		<!-- 主题（主要颜色设置） -->
		<link rel="stylesheet" href="../../css/theme.css" />
		<!-- 通用的css -->
		<link rel="stylesheet" href="../../css/common.css" />
	</head>
	<style>
        #swiper {
            overflow: hidden;
        }
        #swiper .layui-carousel-ind li {
            width: 25px;
            height: 8px;
            border-width: 0;
            border-style: solid;
            border-color: rgba(0,0,0,.3);
            border-radius: 10px;
            background-color: #f7f7f7;
            box-shadow: 0 0 0px rgba(110,22,64,.8);
        }
        #swiper .layui-carousel-ind li.layui-this {
            width: 40px;
            height: 10px;
            border-width: 0;
            border-style: solid;
            border-color: rgba(0,0,0,.3);
            border-radius: 20px;
            background-color: rgba(23, 48, 197, 1);
            box-shadow: 0 0 0px rgba(110,22,64,.8);
        }
        
        .index-title {
            text-align: center;
            box-sizing: border-box;
            width: 980px;
            display: flex;
            justify-content: center;
            align-items: center;
            flex-direction: column;
        }
        .forum-container .btn-container {
            display: flex;
                align-items: center;
                box-sizing: border-box;
                width: 100%;
                flex-wrap: wrap;
        }
        .forum-container .btn-container button i {
            margin-right: 4px;
        }
        
        .layui-laypage .layui-laypage-count {
          padding: 0 10px;
        }
        .layui-laypage .layui-laypage-skip {
          padding-left: 10px;
        }
.paper-container thead tr {
            background-color: rgba(23, 48, 197, 1);
            color: #000;
        }

    </style>
	<body>

		<div id="app">
			<!-- 轮播图 -->
			<!-- <div class="layui-carousel" id="swiper">
				<div carousel-item id="swiper-item">
					<div v-for="(item,index) in swiperList" v-bind:key="index">
						<img class="swiper-item" :src="item.img">
					</div>
				</div>
			</div> -->
			<div class="layui-carousel" id="swiper" :style='{"boxShadow":"0 0 0px rgba(110,22,64,.8)","margin":"0 auto","borderColor":"rgba(0,0,0,.3)","borderRadius":"0px","borderWidth":"0","width":"100%","borderStyle":"solid"}'>
			  <div carousel-item id="swiper-item">
				<div v-for="(item,index) in swiperList" :key="index">
					<img style="width: 100%;height: 100%;object-fit:cover;" :src="item.img" />
				</div>
			  </div>
			</div>
			<!-- 轮播图 -->

			<!-- 标题 -->
			<div class="index-title" :style='{"padding":"10px","boxShadow":"0 0 2px rgba(24, 22, 22, 0.3)","margin":"20px auto","borderColor":"rgba(0,0,0,.3)","backgroundColor":"rgba(23, 48, 197, 1)","color":"rgba(255, 255, 255, 1)","borderRadius":"30px 0px ","borderWidth":"0","fontSize":"20px","borderStyle":"solid","height":"auto"}'>
			  <span>EXAM / PAPER</span><span>热点知识列表</span>
			</div>
			<!-- 标题 -->
			<div class="paper-container">
                <div class="btn-container" :style='{"padding":"0 10px","boxShadow":"0 0 1px rgba(23, 48, 197, 1)","margin":"10px 0 10px 0","borderColor":"rgba(0,0,0,.3)","backgroundColor":"rgba(23, 48, 197, 1)","borderRadius":"4px","alignItems":"center","borderWidth":"0","borderStyle":"solid","justifyContent":"flex-end","height":"64px"}'>
                    <input type="text" style="margin-top: 8px;display: inline;" :style='{"boxShadow":"0 0 0px rgba(255,0,0,0)","borderColor":"rgba(21, 20, 20, 1)","backgroundColor":"#fff","color":"#333","borderRadius":"32px","textAlign":"center","borderWidth":"0.5px","width":"100px","fontSize":"15px","borderStyle":"solid","height":"36px"}' name="title" id="title" placeholder="名称" autocomplete="off" class="layui-input">
                    <button :style='{"padding":"0 15px","boxShadow":"0 0 0px rgba(0,0,0,0)","margin":"0 0 0 10px","borderColor":"#409EFF","backgroundColor":"rgba(241, 58, 58, 1)","color":"#fff","borderRadius":"100px","borderWidth":"0","width":"auto","fontSize":"15px","borderStyle":"solid","height":"40px"}' id="btn-search" type="button" class="layui-btn layui-btn-normal">
                        <i class="layui-icon layui-icon-search"></i>搜索
                    </button>
                </div>
				<table class="layui-table" lay-skin="nob">
					<thead>
						<tr>
							<th>热点知识名称</th>
							<th>考试时长</th>
							<th>创建时间</th>
							<th>操作</th>
						</tr>
					</thead>
					<tbody>
						<tr v-for="(item,index) in dataList" v-bind:key="index">
							<td>{{item.name}}</td>
							<td>{{item.time}}分钟</td>
							<td>{{item.addtime}}</td>
							<td>
								<button @click="exam(item.id)" type="button" class="layui-btn layui-btn-radius btn-theme">
									<i class="layui-icon">&#xe679;</i> 考试
								</button>
							</td>
						</tr>
					</tbody>
				</table>
				<div class="pager" id="pager"  :style="{textAlign:2==1?'left':2==2?'center':'right'}"></div>
			</div>
		</div>

		<!-- layui -->
		<script src="../../layui/layui.js"></script>
		<!-- vue -->
		<script src="../../js/vue.js"></script>
		<!-- 组件配置信息 -->
		<script src="../../js/config.js"></script>
		<!-- 扩展插件配置信息 -->
		<script src="../../modules/config.js"></script>
		<!-- 工具方法 -->
		<script src="../../js/utils.js"></script>

		<script>
			var vue = new Vue({
				el: '#app',
				data: {
					// 轮播图
					swiperList: [{
						img: '../../img/banner.jpg'
					}],
					dataList: []
				},
				filters: {
					newsDesc: function(val) {
						if (val) {
							if (val.length > 200) {
								return val.substring(0, 200).replace(/<[^>]*>/g).replace(/undefined/g, '');
							} else {
								return val.replace(/<[^>]*>/g).replace(/undefined/g, '');
							}
						}
						return '';
					}
				},
				methods: {
					jump(url) {
						jump(url)
					},
					// 进入考试
					exam(id) {
						let userid = localStorage.getItem("userid");
						layui.http.request(`examrecord/deleteRecords?userid=${userid}&paperid=${id}`, 'post', {}, function(res) {
							window.parent.location.href = `./exam.jsp?id=${id}`;
						});
					}
				}
			})

			layui.use(['layer', 'element', 'carousel', 'laypage', 'http', 'jquery'], function() {
				var layer = layui.layer;
				var element = layui.element;
				var carousel = layui.carousel;
				var laypage = layui.laypage;
				var http = layui.http;
				var jquery = layui.jquery;

				var limit = 5;

				// 获取轮播图 数据
				http.request('config/list', 'get', {
					page: 1,
					limit: 5
				}, function(res) {
					if (res.data.list.length > 0) {
						var swiperItemHtml = '';
						for (let item of res.data.list) {
							if (item.name.indexOf('picture') >= 0 && item.value && item.value != "" && item.value != null) {
								swiperItemHtml +=
									'<div>' +
									'<img class="swiper-item" style="width: 100%;height: 100%;object-fit:cover;" src="' + http.baseurl+item.value + '">' +
									'</div>';
							}
						}
						jquery('#swiper-item').html(swiperItemHtml);
						// 轮播图
						vue.$nextTick(() => {
						  carousel.render({
						  	elem: '#swiper',
							width: '100%',
						  	height: '550px',
						  	arrow: 'hover',
						  	anim: 'fade',
						  	autoplay: 'true',
						  	interval: '2900',
						  	indicator: 'inside'
						  });
						
						})
					}
				});

                pageList();
                // 搜索按钮
                jquery('#btn-search').click(function(e) {
                    pageList();
                });
                // 获取列表数据
                function pageList() {
                    http.request('exampaper/list', 'get', {
                        page: 1,
                        limit: limit,
                        name: '%' + jquery('#title').val() + '%',
                        status: 1
                    }, function(res) {
                        vue.dataList = res.data.list
                        // 分页
                        laypage.render({
                            elem: 'pager',
                            count: res.data.total,
                            limit: limit,
                            groups: 5,
                            layout: ["prev","page","next","skip"],
                            theme: '#1730C5',
                            jump: function(obj, first) {
                                //首次不执行
                                if (!first) {
                                    http.request('exampaper/list', 'get', {
                                        page: obj.curr,
                                        limit: obj.limit
                                    }, function(res) {
                                        vue.dataList = res.data.list
                                    })
                                }
                            }
                        });
                    })
                }
			});
		</script>
	</body>
</html>
